﻿using FluentValidation;
using Jupiter.Infrastructure.Domain;
using MediatR;

namespace Wips.AppService.Authorities.Users.Requests
{
    /// <summary>
    /// 修改密码请求类
    /// </summary>
    public class ChangePasswordRequest : IRequest<string>, ITxRequest
    {
        /// <summary>
        /// 
        /// </summary>
        public string CurrentPassword { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string NewPassword { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class ChangePasswordValidator : AbstractValidator<ChangePasswordRequest>
    {
        /// <summary>
        /// 
        /// </summary>
        public ChangePasswordValidator()
        {
            RuleFor(p => p.CurrentPassword)
                .Must(p => !string.IsNullOrEmpty(p))
                .WithMessage("原密码不能为空");
            RuleFor(p => p.NewPassword)
                .Must(p => !string.IsNullOrEmpty(p))
                .WithMessage("新密码不能为空")
                //.Must((p, a) => p.CurrentPassword != a)
                .NotEqual(p=>p.CurrentPassword)
                .WithMessage("原密码不能和新密码一样");
        }
    }
}